//
//  SchemeTableViewCell.m
//  AnXin100
//
//  Created by Sakura on 2018/11/10.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "SchemeTableViewCell.h"

@interface SchemeTableViewCell ()

@property (nonatomic, strong) UILabel *contentLabel;

@property (nonatomic, strong) UILabel *priceLabel;

@property (nonatomic, strong) UIView *lineView;

@property (nonatomic, strong) UIButton *editBtn;

@property (nonatomic, strong) UIButton *deleteBtn;

@property (nonatomic, strong) UIImageView *userImage;

@property (nonatomic, strong) UIButton *issueBtn;
@end

@implementation SchemeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatCell];
    }
    return self;
}

- (void)creatCell {
    
    _userImage = [UIImageView new];
    _userImage.layer.cornerRadius = 25;
    _userImage.layer.masksToBounds = YES;
    _userImage.image = [UIImage imageNamed:@"xy.jpg"];
    [self.contentView addSubview:_userImage];
    
    _contentLabel = [UILabel new];
    _contentLabel.font = FONT_FOURTEEN;
    _contentLabel.textColor = COLOR_Gray;
    _contentLabel.text = @"您好，我的葡萄叶子有点发黄，你看看是不是得霜霉病了";
    [self.contentView addSubview:_contentLabel];
    
    _priceLabel = [UILabel new];
    _priceLabel.font = [UIFont systemFontOfSize:14];
    _priceLabel.textColor = COLOR_ORG;
    _priceLabel.text = @"￥2.00";
    _priceLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:_priceLabel];
    
    _lineView = [UIView new];
    _lineView.backgroundColor = COLOR_LINE;
    [self.contentView addSubview:_lineView];
    
    _editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _editBtn.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
    _editBtn.layer.cornerRadius = 3;
    _editBtn.layer.masksToBounds = YES;
    _editBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [_editBtn setTitle:@"修改" forState:UIControlStateNormal];
    [self.contentView addSubview:_editBtn];
    
    _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _deleteBtn.backgroundColor = COLOR_ORG;
    _deleteBtn.layer.cornerRadius = 3;
    _deleteBtn.layer.masksToBounds = YES;
    _deleteBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [_deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
    [self.contentView addSubview:_deleteBtn];
    
    _issueBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _issueBtn.backgroundColor = COLOR_GREEN;
    _issueBtn.layer.cornerRadius = 3;
    _issueBtn.layer.masksToBounds = YES;
    _issueBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [_issueBtn setTitle:@"发布" forState:UIControlStateNormal];
    [self.contentView addSubview:_issueBtn];
    
}

- (void)layoutSubviews {
    
    _userImage.frame = CGRectMake(10, 15, 50, 50);
    _priceLabel.frame = CGRectMake(SCREEN_WIDTH - 80, 30, 70, 20);
    _lineView.frame = CGRectMake(0, 80, SCREEN_WIDTH, 1);
//    _editBtn.frame = CGRectMake(SCREEN_WIDTH - , 80, 65, 25)
    
}

- (void)setType:(SchemeType)type {
    
    if (type == PassScheme) {
        
        _userImage.alpha = 1;
        _contentLabel.frame = CGRectMake(70, 30, SCREEN_WIDTH - 160, 20);
        _deleteBtn.frame = CGRectMake(SCREEN_WIDTH - 75, 90, 65, 25);
        _editBtn.frame = CGRectMake(CGRectGetMinX(_deleteBtn.frame) - 75, 90, 65, 25);
        _issueBtn.alpha = 0;
        
    } else if (type == StayScheme) {
        
        _userImage.alpha = 0;
        _contentLabel.frame = CGRectMake(10, 30, SCREEN_WIDTH - 90, 20);
        _deleteBtn.frame = CGRectMake(SCREEN_WIDTH - 75, 90, 65, 25);
        _editBtn.frame = CGRectMake(CGRectGetMinX(_deleteBtn.frame) - 75, 90, 65, 25);
        _issueBtn.alpha = 0;
        
    } else {
        _userImage.alpha = 0;
        _contentLabel.frame = CGRectMake(10, 30, SCREEN_WIDTH - 90, 20);
        _issueBtn.alpha = 1;
        _issueBtn.frame = CGRectMake(SCREEN_WIDTH - 75, 90, 65, 25);
        _deleteBtn.frame = CGRectMake(CGRectGetMinX(_issueBtn.frame) - 75, 90, 65, 25);
        _editBtn.frame = CGRectMake(CGRectGetMinX(_deleteBtn.frame) - 75, 90, 65, 25);

    }
}


- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
